﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;
using ProjectBase.Core.Web;
using ProjectBase.Mvc;
using ProjectBase.Mvc.Controllers;

using Survey.Common;
using Survey.Common.Business.Services;
using Survey.Common.Controllers.Services;
using Survey.Common.Models.Services;
using Survey.Entity.Services;

namespace Survey.Mvc.Controllers.Services
{
    public class LanguageController
        : EntityController<Language, LanguageFilter, ILanguageModel, ILanguageFacade>, ILanguageController
    {
        #region OnList
        /// <summary>
        ///     Set columns for List View
        /// </summary>
        protected override IEnumerable<IItemToDisplay> LoadItemsToDisplay(LanguageFilter filter)
        {
            return Facade.Find(filter)
                .Select(i => new ItemToDisplay
                {
                    ID = i.IDToDisplay,
                    Description = i.ToDisplay(),
                    Items = new List<ICellDescription>
                    {
                        i.Cell(() => i.LanguageName),
                        i.Cell(() => i.EnglishName),
                        i.Cell(() => i.NativeName),
                        i.Cell(() => i.ShowFlag),
                        i.Cell(() => i.ID, new CellDescription {Align = Align.right, Format = "N0"}),
                    }
                } as IItemToDisplay);
        }

        /// <summary>
        ///     Provides columns for Excel
        /// </summary>
        protected override IEnumerable<IEnumerable<IExCell>> LoadExcelItemsToDisplay(LanguageFilter filter)
        {
            return Facade.Find(filter)
                .Select(i => new List<IExCell>
                {
                    i.ExCell(() => i.ID),
                    i.ExCell(() => i.LanguageName),
                    i.ExCell(() => i.EnglishName),
                    i.ExCell(() => i.NativeName),
                    i.ExCell(() => i.ShowFlag),
                });
        }
        #endregion OnList

        #region abstract ClearFilter
        /// <summary>
        ///     Pre-sets filtering filters
        /// </summary>
        protected override LanguageFilter ClearFilter()
        {
            var filter = base.ClearFilter();
            // TODO set the MVC defaults e.g.: filter.OrderBy["ID"] = false;
            return filter;
        }
        #endregion ClearFilter

        #region properties
        public override string ControllerName
        {
            get { return Str.Controllers.Language; }
        }
        #endregion properties
    }
}